﻿<%

Function HTML2WML2(strHTML, doNextLine)
  if isEmpty(strHTML) or isNull(strHTML)  then
      exit function
  end if

  dim strOutput
  strOutput = strHTML
  strOutput = Replace(strOutput, chr(10), " ")
  strOutput = Replace(strOutput, chr(13), "")
  
  Dim objRegExp
  Set objRegExp = New RegExp
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  
  if doNextLine then
	  objRegExp.Pattern = "<P[^<>]*>"
	  strOutput = objRegExp.Replace(strOutput, chr(10))
	
	  objRegExp.Pattern = "<DIV[^<>]*>"
	  strOutput = objRegExp.Replace(strOutput, chr(10))
	
	  objRegExp.Pattern = "<BR[^<>]*>"
	  strOutput = objRegExp.Replace(strOutput, chr(10))
  end if
    
  'Replace all HTML tag matches with the empty string
  objRegExp.Pattern = "<[^<>]+>"
  strOutput = objRegExp.Replace(strOutput, "")
  
  strOutput = Replace(strOutput, "&nbsp;", " " )
  strOutput = Replace(strOutput, "&amp;", "&" )
  strOutput = Replace(strOutput, "&#36;", CHR(36) )
  strOutput = Replace(strOutput, "&#39;", CHR(39) )
  strOutput = Replace(strOutput, "&lt;", "<" )
  strOutput = Replace(strOutput, "&gt;", ">" )
  strOutput = Replace(strOutput, "&", "&amp;" )
  strOutput = Replace(strOutput, "<", "&lt;")
  strOutput = Replace(strOutput, ">", "&gt;")
  strOutput = Replace(strOutput, chr(10), "<br/>")
  
  HTML2WML2 = strOutput    'Return the value of strOutput

  Set objRegExp = Nothing
End Function

Function HTML2WML(strHTML)
  HTML2WML = HTML2WML2(strHTML,true)
End function

const WML_TXT_PAGE_SIZE=2000
  
  
function wmlTxtPage(text, curPageNo)
    if isEmpty(curPageNo) or clng(curPageNo)<1 then
        curPageNo =1 
    end if  
    wmlTxtPage = text
    if not isEmpty(text) then
  		wmlTxtPage = HTML2WML(strMid(text, (curPageNo-1)*WML_TXT_PAGE_SIZE+1,  WML_TXT_PAGE_SIZE))
  	end if
  end function
  
 function wmlTxtPageLink(text, curPageNo, url)
 	wmlTxtPageLink = wmlTxtPageLink2(text, curPageNo, url, "pageno")
 end function
 
 Function wmlTxtPageLink2(text, curPageNo, url, pageName)
    dim totalSize, pageSize
    
    pageSize = WML_TXT_PAGE_SIZE
    totalSize = strLen(text)  
     if isNull(totalSize) or isEmpty(totalSize) or clng(totalSize)<1 then
        totalSize =1 
    end if
    totalSize = clng(totalSize)


    wmlTxtPageLink2 = wmlPageLink2(curPageNo, pageSize, totalSize, url, pageName)
  End Function

  Function wmlPageLink(curPageNo, pageSize, totalSize, url)
  	wmlPageLink = wmlPageLink2(curPageNo, pageSize, totalSize, url, "pageno")
  End Function  

  Function wmlPageLink2(curPageNo, pageSize, totalSize, url, pageName)
    dim wmlCode, totalPage
    
    if isNull(totalSize) or isEmpty(totalSize) or clng(totalSize)<1 then
        totalSize =1 
    end if
    totalSize = clng(totalSize)

    if isEmpty(pageName)  then
        pageName = "pageno"
    end if    
        
    if isEmpty(curPageNo) or clng(curPageNo)<1 then
        curPageNo =1 
    end if
    curPageNo = clng(curPageNo)
    
    totalPage = (totalSize + pageSize -1) \ pageSize

    if InStrRev(url,"?")<1 then
      url = url & "?"
    else
        url  = url & "&amp;"
    end if

    wmlCode = "" 
    
    if totalPage>1 then
	
	    if (curPageNo<totalPage) then
	      wmlCode = wmlCode & "<a href='" & url & pageName & "=" & (curPageNo+1) & "'>下页</a>,"
	    end if

	    if (curPageNo>1) then
	      wmlCode = wmlCode & "<a href='" & url & pageName & "=" & (curPageNo-1) & "'>上页</a>,"
	    end if
	    	    
	    dim i, sPageNo, ePageNo
	    sPageNo = curPageNo - 3
	    
	    if totalPage - curPageNo<5 then 
	    	sPageNo = totalPage-7
		end if
		
	    if sPageNo<2 then
	        sPageNo=2
	    end if

	    ePageNo = curPageNo + 4
	    if curPageNo<4 then 
	    	ePageNo = 8
		end if
			    
	    if ePageNo>totalPage-1 then
	        ePageNo = totalPage-1
	    end if
	    wmlCode = wmlCode & "第"
	    if curPageNo=1 then 
	      wmlCode = wmlCode & "1,"
	    else
	      wmlCode = wmlCode & "<a href='" & url & pageName & "=" & 1 & "'>" & 1 & "</a>,"
	    end if
	    
	    for i=sPageNo to ePageNo
	      
	      if i=curPageNo then
	        wmlCode = wmlCode & i & ","
	      elseif i=sPageNo and sPageNo<>2 then
	        wmlCode = wmlCode & "<a href='" & url & pageName & "=" & i & "'>..</a>,"
	      elseif i=ePageNo and ePageNo<>totalPage-1 then
	        wmlCode = wmlCode & "<a href='" & url & pageName & "=" & i & "'>..</a>,"
	      else
	        wmlCode = wmlCode & "<a href='" & url & pageName & "=" & i & "'>" & i &  "</a>,"
	      end if
	      
	    next  
	    
	    if curPageNo=totalPage then 
	      wmlCode = wmlCode & totalPage
	    else
	      wmlCode = wmlCode & "<a href='" & url & pageName & "=" & totalPage & "'>" & totalPage & "</a>"
	    end if
	    wmlCode = wmlCode & "页"
	    

	end if
	
    wmlPageLink2 = wmlCode
  end function
  


Sub writeBlogOptions
  response.write "<do type='prev' label='后退'><prev /></do>"
  
  if request("blog_id") <> "" then
      response.write "" &_
        "<do type='accept' label='" & blogObj.blogTitle & "首页' name='_blogindex'> " & vbCrLf &_
        "    <go href='list.asp' method='get'> " & vbCrLf &_
        "        <postfield name='blog_id' value='" & blogObj.blogId & "'/> " & vbCrLf &_
        "    </go>  " & vbCrLf &_
        "</do> "
  end if
  
  
  if request("content_id") <> "" and userRightObj.canReply then
      response.write "" &_
        "<do type='accept' label='发表评论' name='_reply'> " & vbCrLf &_
        "    <go href='reply.asp' method='get'> " & vbCrLf &_
        "        <postfield name='blog_id' value='" & blogObj.blogId & "'/> " & vbCrLf &_
        "        <postfield name='content_id' value='" & request("content_id") & "'/> " & vbCrLf &_
        "    </go>  " & vbCrLf &_
        "</do> "
  end if

  if not userObj.isFound then
    response.write "" &_
      "<do type='accept' label='用户登录' name='_login'> " & vbCrLf &_
      "    <go href='login.asp' method='get'> " & vbCrLf &_
      "        <postfield name='blog_id' value='" & blogObj.blogId & "'/> " & vbCrLf &_
      "    </go>  " & vbCrLf &_
      "</do> "
  else
      if request("blog_id")<>"" and userRightObj.canPost then
        response.write "" &_
          "<do type='accept' label='发布文章' name='_posttxt'> " & vbCrLf &_
          "    <go href='edit.asp' method='get'> " & vbCrLf &_
          "        <postfield name='blog_id' value='" & blogObj.blogId & "'/> " & vbCrLf &_
          "    </go>  " & vbCrLf &_
          "</do> "
      end if
      if not isEmpty(userObj.blog) then
         if not isEmpty(userObj.blog.blogId) and userObj.blog.blogId<>blogObj.blogId then
            response.write "" &_
              "<do type='accept' label='我的Blog' name='_myblog'> " & vbCrLf &_
              "    <go href='list.asp' method='get'> " & vbCrLf &_
              "        <postfield name='blog_id' value='" & userObj.blog.blogId & "'/> " & vbCrLf &_
              "    </go>  " & vbCrLf &_
              "</do> "
         end if
       end if
  end if


  response.write "" &_
    "<do type='accept' label='Blog列表' name='_bloglist'> " & vbCrLf &_
    "    <go href='blogs.asp' method='get'> " & vbCrLf &_
    "    </go>  " & vbCrLf &_
    "</do> "
    

  response.write "" &_
    "<do type='accept' label='最新文章' name='_newentrylist'> " & vbCrLf &_
    "    <go href='list.asp' method='get'> " & vbCrLf &_
    "    </go>  " & vbCrLf &_
    "</do> "

  response.write "" &_
    "<do type='accept' label='最新评论' name='_newcommentslist'> " & vbCrLf &_
    "    <go href='comments.asp' method='get'> " & vbCrLf &_
    "        <postfield name='blog_id' value='" & request("blog_id") & "'/> " & vbCrLf &_
    "    </go>  " & vbCrLf &_
    "</do> "

  response.write "" &_
    "<do type='accept' label='站点首页' name='_index'> " & vbCrLf &_
    "    <go href='index.asp' method='get'> " & vbCrLf &_
    "    </go>  " & vbCrLf &_
    "</do> "
    
End Sub
%>